unit AppWaterTestsTable;

{$mode objfpc}{$H+}

//========================================================================================
//
// Unit : AppWaterTestsTable.pas
//
// Description : This routine handles all functionality of the WaterTests Table.
//               The Table consists of a series of records detailing all requirements
//               for the tests required to manitain Water Quality of Aquariums.
//
// Called By :
//
// Calls :
//
// Ver. : 1.0.0
//
// Date : 31 Oct 2015
//
//========================================================================================

interface

uses
  Classes, SysUtils, dbf, sqldb, sqlite3conn, db, FileUtil, Forms, Controls,
  Graphics, Dialogs, Grids, Buttons, DBGrids;

//type

  { TfrmAppWaterTestsTable }

{  TfrmAppWaterTestsTable = class(TForm)
    bbtCancel: TBitBtn;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    SQLQuery1: TSQLQuery;
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    procedure CreateWaterTestsTable;
  end;// TfrmAppWaterTestsTable       }

//var
//  frmAppWaterTestsTable: TfrmAppWaterTestsTable;

implementation

{$R *.lfm}

uses
  ApplicationDataModule;

//========================================================================================
//          PRIVATE ROUTINES
//========================================================================================

//========================================================================================
//          PUBLIC ROUTINES
//========================================================================================
{procedure TfrmAppWaterTestsTable.CreateWaterTestsTable;
var
  vstrTStr : string;
begin

{  showmessage('Creating WaterTests Table');
  dmApplication.SQLTransactionApp.Active := true;

  // Here we're setting up a table named "DATA" in the new database
  dmApplication.SQLite3ConnectionApp.ExecuteDirect('CREATE TABLE "WaterTestsTable"(' +
  ' "Test_ID" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,' +
  ' "Test_Name" CHAR[20] NOT NULL,' +
  ' "Description" CHAR[128],' +
  ' "Units" CHAR[10],' +
  ' "MinValue" Float NOT NULL,' +
  ' "MaxValue" Float NOT NULL,' +
  ' "TargetValue" Float NOT NULL);');

  // Creating an index based upon id in the DATA Table
  dmApplication.SQLite3ConnectionApp.ExecuteDirect('CREATE UNIQUE INDEX ' +
                                  '"WaterTestsTable_id_idx" ON "WaterTestsTable"( "Test_ID" );');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect('CREATE UNIQUE INDEX ' +
                              '"WaterTestsTable_Name_idx" ON "WaterTestsTable"( "Test_Name" );');
  dmApplication.SQLTransactionApp.Commit;

  // Now we add the Table Entries
  dmApplication.SQLTransactionApp.Active := true;
  // Setup the fixed part of the transaction
  vstrTStr := 'Insert Into "WaterTestsTable"' +
       '("Test_Name", "Description", "Units", "MinValue", "MaxValue",' +
       ' "TargetValue") Values ';

  // Now add each Entrie
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Temperature (Deg C)", "Temperature Celcius Description", "Deg C", 24.0, 26.0, 25.0);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Temperature (Deg F)", "Temperature Farenheight Description", "Deg F", 75.0, 79.0, 77.0);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Salinity", "Salinity Description", "SG", 1.023, 1.025, 1.024);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Alkalinity (KH)", "Alkalinity KH Description", "KH", 7.0, 12.0, 9.5);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Alkalinity (KH ppm)", "Alkalinity KH ppm Description", "KH ppm", 7.0, 12.0, 9.5);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Calcium", "Calcium CA2+ Description", "CA2 ppm", 425.0, 450.0, 437.5);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Nitrate", "Nitrate NO3 Description", "NO3 ppm", 0.0, 10.0, 0.0);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Phosphate", "Phosphate PO3- Description", "PO3 ppm", 0.0, 0.05, 0.0);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Nitrite", "Nitrite NO2 Description", "NO2 mg/L", 0.0, 99.0, 0.0);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("PH", "PH Description", "PH ", 7.5, 8.7, 8.1);');
  dmApplication.SQLite3ConnectionApp.ExecuteDirect( vstrTStr +
       '("Ammonia", "Ammonia NH3/4 Description", "NH3/4 ppm", 0.0, 0.0, 0.0);');

  // Commit the transactions
  dmApplication.SQLTransactionApp.Commit;

  ShowMessage('Succesfully Created WaterTests Table.');  }

end;// TfrmAppWaterTestsTable.CreateWaterTestsTable }

//========================================================================================
//          PUBLISHED ROUTINES
//========================================================================================

//========================================================================================
//          SUPPORT ROUTINES
//========================================================================================

//========================================================================================
//          MENU ROUTINES
//========================================================================================

//========================================================================================
//          FILE ROUTINES
//========================================================================================

//========================================================================================
//          COMMAND BUTTON ROUTINES
//========================================================================================

//========================================================================================
//          CONTROL ROUTINES
//========================================================================================

//========================================================================================
//          TOOLBAR ROUTINES
//========================================================================================

//========================================================================================
//           STATUSBAR ROUTINES
//========================================================================================

//========================================================================================
//          DATABASE ROUTINES
//========================================================================================

//=========================
//  OnChange Routines
//=========================

//=========================
//  OnClick Routines
//=========================

//=========================
//  OnKeypress Routines
//=========================

//========================================================================================
//          FORM ROUTINES
//========================================================================================
{procedure TfrmAppWaterTestsTable.FormShow(Sender: TObject);
begin
//  dmApplication.SQLTransactionApp.Active := true;
//  SQLQuery1.Active := True;

end;// procedure TfrmAppWaterTestsTable.FormShow     }

//========================================================================================
end.// unit WaterTestsTable

